Spring can commit Transaction in finally block with RunTimeException in try block [migrated]

Posted by Chance Lai on Programmers See other posts from Programmers or by Chance Lai
Published on 2012-11-13T15:09:53Z Indexed on 2012/11/13 17:17 UTC
Read the original article Hit count: 322

Filed under:
|
|
|

The project used Spring + Hibernate

Sample code:

public void method(){    
   try{  
     dao.saveA(entityA);  
     throw RuntimeException;  
     dao.saveB(entityB);  
    }catch(RuntimeException e){  
     throw e;  
    }finally{  
      dao.saveC(entityC)  
    }  
}

Finally, just entityC will be saved in database in test.
I think saveA, saveB, saveC in the same transaction,they should not be committed.
In this case, I want to know why entityC is committed.
How does Spring do this in the finally block?

© Programmers or respective owner

Related posts about java

Related posts about spring